<template>
  <div style="padding:15px;">
    <div style="background-color: white;height: 800px; overflow: auto">
      <div class="clearfix">
        <el-input
          class="searchDepartment"
          placeholder="输入项目编号搜索项目"
          prefix-icon="el-icon-search"
          v-model="searchContent"
          style="margin: 15px 15px;width: 250px;float: left"
          @input = "searchProject">
        </el-input>
      </div>
      <div style="margin: 0 15px;">
        <el-table
          :data="deleteTable"
          stripe
          border
          style="width: 100%;"
          :header-cell-style="{background:'#eef1f6',color:'#606266'}">
          <el-table-column
            prop="number"
            label="项目编号">
          </el-table-column>
          <el-table-column
            prop="projectName"
            label="项目名称">
          </el-table-column>
          <el-table-column
            prop="missionNumber"
            label="任务数">
          </el-table-column>
          <el-table-column
            prop="cp"
            label="创建人">
            <template slot-scope="scope">
              <el-avatar style="float:left; margin-top:3px;" size="small" :src="scope.row.creatorHeadImg" ></el-avatar>
              <span style="float:left;margin-left: 5px;margin-top: 8px">{{ scope.row.creatorName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="dp"
            label="删除人">
            <template slot-scope="scope">
              <el-avatar style="float:left; margin-top:3px;" size="small" :src="scope.row.deleterHeadImg" ></el-avatar>
              <span style="float:left;margin-left: 5px;margin-top: 8px">{{ scope.row.deleterName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="deleteDate"
            label="删除时间">
          </el-table-column>
          <el-table-column
            prop="operate"
            label="操作">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="dark" content="激活" placement="bottom">
                <el-icon
                  class="el-icon-refresh-right"
                  @click.native="activate(scope.$index, scope.row)"
                  style="cursor: pointer"></el-icon>
              </el-tooltip>
<!--              <el-tooltip class="item" effect="dark" content="删除" placement="bottom">-->
<!--                <el-icon-->
<!--                  class="el-icon-close"-->
<!--                  @click.native="deleteProject(scope.$index, scope.row)"-->
<!--                  style="margin-left: 10px;cursor: pointer"></el-icon>-->
<!--              </el-tooltip>-->
            </template>
          </el-table-column>
        </el-table>
        <div style="text-align: center;margin-top: 10px">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5,6,7,8]"
            :page-size= "PageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total= "total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
  const axios = require('axios');
    export default {
        name: "deletedProjects",
      data() {
          return {
            searchContent: '',
            currentPage: 1,
            total: 0,
            PageSize: 5,

            // //判断是否在进行搜索
            // isSearch:0,

            deleteTable: [],
          }
      },
      created(){
        axios.post('/findAllDeleteProjectTable',{"id":window.localStorage.getItem("id"),"pageCode":this.currentPage,"pageSize":this.PageSize,
          "content":this.searchContent,"enterpriseId":window.localStorage.getItem("enterprise_id")}).then(res => {
          this.deleteTable = res.data.list;
          this.total = res.data.total;
        })
      },
      methods: {
        handleSizeChange(val) {
          this.PageSize = val;
            axios.post('/findAllDeleteProjectTable',{"id":window.localStorage.getItem("id"),"pageCode":this.currentPage,"pageSize":this.PageSize,
              "content":this.searchContent,"enterpriseId":window.localStorage.getItem("enterprise_id")}).then(res => {
              this.deleteTable = res.data.list;
              this.total = res.data.total;
            })
        },
        handleCurrentChange(val) {
          this.currentPage = val;
            axios.post('/findAllDeleteProjectTable',{"id":window.localStorage.getItem("id"),"pageCode":this.currentPage,"pageSize":this.PageSize,
              "content":this.searchContent,"enterpriseId":window.localStorage.getItem("enterprise_id")}).then(res => {
              this.deleteTable = res.data.list;
              this.total = res.data.total;
            })
        },

        searchProject() {
          this.currentPage = 1;
          axios.post('/findAllDeleteProjectTable',{"id":window.localStorage.getItem("id"),"pageCode":this.currentPage,"pageSize":this.PageSize,
            "content":this.searchContent,"enterpriseId":window.localStorage.getItem("enterprise_id")}).then(res => {
            this.deleteTable = res.data.list;
            this.total = res.data.total;
          })
        },

        activate(index, row) {
          this.$confirm('确定要激活该项目吗?该项目的任务并不会同时激活，需自己手动去激活', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            center: true
          }).then(() => {
            axios.post("/updateDeleteProject",{"id":row.id}).then(res => {
              if(res.data = 1){
                this.currentPage = 1;
                axios.post('/findAllDeleteProjectTable',{"id":window.localStorage.getItem("id"),"pageCode":this.currentPage,"pageSize":this.PageSize,
                  "content":this.searchContent,"enterpriseId":window.localStorage.getItem("enterprise_id")}).then(res => {
                  this.deleteTable = res.data.list;
                  this.total = res.data.total;
                })
                this.$message({
                  type: 'success',
                  message: '激活成功!'
                });
              }else{
                this.$message.error("激活失败")
              }
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消激活'
            });
          });
        },

        // deleteProject(index,row) {
        //   this.$confirm('删除之后会将和该项目有关的数据全部删除，确定要删除该项目吗?', '提示', {
        //     confirmButtonText: '确定',
        //     cancelButtonText: '取消',
        //     type: 'warning',
        //     center: true
        //   }).then(() => {
        //     axios.post("/deleteProject",{"id":row.id}).then(res => {
        //       if(res.data == 0){
        //         this.currentPage = 1;
        //         axios.post('/findAllDeleteProjectTable',{"id":window.localStorage.getItem("id"),"pageCode":this.currentPage,"pageSize":this.PageSize,
        //           "content":this.searchContent,"enterpriseId":window.localStorage.getItem("enterprise_id")}).then(res => {
        //           this.deleteTable = res.data.list;
        //           this.total = res.data.total;
        //         })
        //         this.$message({
        //           type: 'success',
        //           message: '删除成功!'
        //         });
        //       }else{
        //         this.$message.error("删除失败")
        //       }
        //     })
        //   }).catch(() => {
        //     this.$message({
        //       type: 'info',
        //       message: '已取消删除'
        //     });
        //   });
        // }
      }
    }
</script>

<style scoped>

</style>
